Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to ignore a folder we directly add in the same commit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a deterrant, changes to this directory will have warnings, and developers will need to force add new files

Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,6 @@ _Pvt_Extensions/
ModelManifest.xml

.cache/

# Visual Studio Code
.vscode/
11 changes: 11 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-vscode.cmake-tools", // CMake for Debugging C/C++
"vs-code-extensions.vscode-clangd", // Optional intellisense-like features with LLVM/clangd

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not the original llvm-vs-code-extensions.vscode-clangd?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how did I screw up the copy, I'll update it

"daohong-emilio.yash", // For flex/bison source files

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is not available in open-vsx; I've searched and found a full-fledged new extension https://github.com/theodevelop/bison-flex-lang - should we recommend that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fresh out of the oven for a week, just tested it feels a bit rough, very active development, looks good, so the name is theodevelop.bison-flex-lang on both repository, I'll update it
https://marketplace.visualstudio.com/items?itemName=theodevelop.bison-flex-lang
https://open-vsx.org/extension/theodevelop/bison-flex-lang

],
}
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "lldb",
"request": "launch",
// Resolved by CMake Tools:
"program": "${command:cmake.launchTargetPath}",
// "--header-file=<output_header>", "-o<output_source>", "<input_source>"
"args": [
"calc.l",
],
"cwd": "${workspaceFolder}/../flex-bison-example",
"terminal": "integrated",
"stopOnEntry": false,
// Non-Windows is unnecessary but it helps to ensure
"env": {
"PATH": "${env:PATH}:${command:cmake.launchTargetDirectory}"
},
"windows": {
// Warning: CodeLLDB is still slower than WinDbg (cppvsdbg) in Windows
// and don't support C++ (string/vector) for MSVC ABI - this code base is C99
"env": {
"PATH": "${env:PATH};${command:cmake.launchTargetDirectory}"
}
},
"initCommands": [
"settings set target.process.follow-fork-mode parent"
]
},
]
}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems those settings would best be user-scope, not specific to this workspace.
Please share your reasoning if your disagree.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workspace is the appropriate place for codebase consistency settings, unless that is something we don't want...

First is editor settings, most users have different settings which will make the codebase inconsistent, the proper way to have consistent code is clang-format, but that will format the whole code instead being just limited to the addtional lines introduced by developers; and will probably make it more difficult to sync with upstream.
Trailing whitespace is undesirable, for consistency and nothing much to explain further

Ruler indicator is just a mindful/useful indicator, I see GNU have an unwritten rule of 80 character line limit, but some codes go up to 120 chars in flex/bison, I'll say this is optional, I can remove this if you don't like to see these lines

The git operations are minimal and good to have for new developers, it helps to ensure git pull in vscode don't branch and merge, prune is optional as it helps to cleanup deleted branches in origin just that the code base is not super active at the moment

CMake preferred generator won't mess up the system as it only uses Ninja if its installed, although the codebase is small, it approximately halves the compilation time for debugging

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workspace is the appropriate place for codebase consistency settings, unless that is something we don't want...

Usually you don't want this, since users will mess with that around and accidentally push private & personal settings / metadata.

the proper way to have consistent code is clang-format, but that will format the whole code instead being just limited to the addtional lines introduced by developers

It doesn't necessarily format the whole base, you can just configure it to only format modified lines. And it's totally in the scope of the contributing developer.

@jonnysoe jonnysoe Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Febbe ,

accidentally push private & personal settings / metadata

Personal settings stay within their user directory settings.json by default when changes are made from the GUI, so if the contributor manually does questionable changes for the code base, then catching questionable changes or they're justifiable is what reviewers are here for

It doesn't necessarily format the whole base

I don't recall git clang-format limits changes to the modified lines back in llvm 15

@Febbe Febbe Mar 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve been using git clang-format for much longer, and its sole purpose is to only operate on the modified lines.
There used to be a run-clang-format.py script that formatted everything.
Additionally, you can configure clangd in VS Code as the formatter for C/C++, and restrict it to formatting only modified lines. That has the same effect as git-clang-format as clangd linked clang-format into its server.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know of the extension being able to format by lines, I just couldn't get it to work when I use command line...

"editor.insertSpaces": true,
"editor.tabSize": 4,
"editor.detectIndentation": true,
"files.trimTrailingWhitespace": true,
"[markdown]": {
"files.trimTrailingWhitespace": false,
},
"editor.rulers": [80,120],
"git.rebaseWhenSync": true,
"git.pruneOnFetch": true,
// "cmake.preferredGenerators": ["Ninja Multi-Config"],
"cmake.generator": "Ninja Multi-Config",
"cmake.options.statusBarVisibility": "compact",
"cmake.useCMakePresets": "never",
"C_Cpp.intelliSenseEngine": "disabled",
}
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endforeach()
message(STATUS "Using /MT STATIC runtime")
endif ()

# MSVC's incremental linking is offering little to no benefit,
# disable it for faster link times (and prevent ilk binary bloat).
# NOTE: Frequent build with vscode is hitting resource busy for the the ilk files.
add_link_options("/INCREMENTAL:NO")
endif ()
endif ()

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ The release page includes the full Changelog but you may also see the [changelog

## HowTo

You may use win_flex and win_bison directly on the command line or [use them via CustomBuildRules in VisualStudio](custom_build_rules/README.md).
You may:
- use `win_flex` and `win_bison` directly on the command line
- [use them via CustomBuildRules in VisualStudio](custom_build_rules/README.md).
- use them via [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) in [Visual Studio Code](vscode/README.md).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that those would also be useful with the bison/flex extension noted above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not getting this statement, mind elaborating more?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GitMensch
Just rereading this, I believe you mean naming the flex/bison extension here, however the extension does not contribute to this HowTo (build/debug), this extension is purely convenience for the developer (goto definition, syntax highlighting, etc. basically things that makes code navigation a pleasant experience)
I don't think we should name it as required (hence its a recommended extension that appears in the extensions list), basically optional like telling ppl "you should use git for this code base", something that we don't need to spell out, it will work regardless.
Lemme know if you still wanna add it here, I can do that, its just a simple "and" statement.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may actually use them in vscode compatible environments (like an open build as VSCodium [used also as vscode in arch] or even Eclipse Thea) - I'd personally prefer replacing the product name of the MS binaries to just "vscode"...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, there is some form of genericization, how does "vscode-like editor" sound?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The referenced file is not about how to use it in vscode, so we may drop the link altogether (and/or add another leading to # How To Use WinFlexBison and # How To Compile/Debug WinFlexBison where we reference the build scripts and the new vscode readme.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This falls under How to Debug, and implicitly Compile, how do you want to split this actually? Under the 2 headers you mentioned?



## Example flex/bison files
Expand Down
Binary file added vscode/1_compiler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscode/2_target.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscode/3_build.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscode/4_breakpoint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscode/5_launch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vscode/6_pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions vscode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

Alternatively, VS Code is available for debugging, here is a simple guide (based on the [MS documentation](https://code.visualstudio.com/docs/cpp/cmake-linux)):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A file starting with "Alternatively" seems bad.
If this file is only about how to debug winflexbison (which is fine and seems to be the case), we can just drop most of the first sentence and instead use a header like # Debugging WinFlexBison in vscode.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is part of the vestige from original cut/paste, I've tried to update most of the things here, missed this 1

1. Make sure the [Prerequisites](https://code.visualstudio.com/docs/cpp/cmake-linux#_prerequisites) are installed.
2. [Select a compiler kit](https://code.visualstudio.com/docs/cpp/cmake-linux#_select-a-kit), any of the native `amd64` version of MSVC is recommended for compatibility - any of the rest with `x86` is cross-compiling a 32-bit version of `win_flex`/`win_bison`.

![Select a compiler kit](./1_compiler.png)

NOTE: Click `Scan for kits` when setting up C/C++ debugging for the first time if there is no compiler kits found yet.

3. Due to `win_flex`/`win_bison` being separate executables/targets, debugging will need to [select a launch target](https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/debug-launch.md#select-a-launch-target).

![Select a launch targe](./2_target.png)

4. Optionally switch between build types - usually between `Release` or `Debug` builds, make sure `Debug` is selected when debugging or there will be no debug symbols to hit breakpoints.

![Debug build type](./3_build.png)

5. Both `win_flex` and `win_bison` requires arguments for the target input/output source files, just add the arguments as how `win_flex` or `win_bison` was called from the command line where each space-separated argument is an element in [.vscode/launch.json](.vscode/launch.json)'s `args` array separated by commas, based on [flex-bison-example](https://github.com/meyerd/flex-bison-example),
- here is a sample for `win_flex` target:
```json
"args": [
"calc.l"
],
```
- here is a sample for `win_bison` target:
```json
"args": [
"--header-file=sample.tab.h",
"-osample.tab.c",
"sample.l"
],
```
- NOTE: This example uses source files without full path was achieved by setting `cwd`
```json
"cwd": "${workspaceFolder}/../flex-bison-example",
```

6. Setup the codebase for inspection [debugging](https://code.visualstudio.com/docs/editor/debugging), eg. breakpoints (with `F9`), [logpoints](https://github.com/vadimcn/codelldb/blob/master/MANUAL.md#logpoints).

![Breakpoint](./4_breakpoint.png)

7. Hit `F5` to start debugging, or click the `launch` button.

![Launch](./5_launch.png)

8. Here is how it looks like when the program pauses at a breakpoint, refer to the official [Debugging guide](https://code.visualstudio.com/docs/debugtest/debugging#_debugger-user-interface) for more information.

![Pause](./6_pause.png)
Loading